--[圆形结构]--

local circle = {}
setmetatable(circle, circle)
ac.circle = circle

-- 创建
function circle:__call(...)
	local x, y, r
	if select('#', ...) == 3 then
		x, y, r = ...
	elseif select('#', ...) == 2 then
		local p
		p, r = ...
		x, y = p:get_point():get()
	end
	return setmetatable({ x = x, y = y, range = r, }, circle)
end

local mt = {}
circle.__index = mt

-- 结构类型
mt.type = 'circle'

-- 圆心
mt.x = 0

-- 圆心
mt.y = 0

-- 半径
mt.range = 32.0

-- 取值
function mt:get()
	return self.x, self.y, self.range
end

-- 获取位置
function mt:get_point()
	return ac.point(self.x, self.y)
end

--- 物体是否在区域内
function mt:has(dest)
	local x1, y1 = self.x, self.y
	local x2, y2 = dest:get_point():get()
	local x0, y0 = x1 - x2, y1 - y2
	return math.sqrt(x0 * x0 + y0 * y0) <= self.range
end

-- 获取随机点
function mt:random()
	local r = math.sqrt(math.random(0, self.range ^ 2))
	local a = math.random(0, 360)
	return ac.point(self.x + r * math.cos(a), self.y + r * math.sin(a))
end

return circle
